Table of Contents
Creating Watermark

To create page watermark, you simply place text or image on the page before placing other contents on the page. A good place to create watermark is in AcmRender's BeforeRenderPage event handler. This event is called when AcmRender is about to render contents on a new page but has not yet placed any output on the page yet. Because the "normal" contents are rendered through AcmRender, "special" contents like watermark are usually rendered directly with low level contents API.

The following code creates a "CONFIDENTIAL" watermark on the output page:

private void CreatePdf()
{        
    //Create a PdfDocument object
    PdfDocument doc = new PdfDocument();

    //Create the render
    AcmRender render = new AcmRender(doc);
    
    //Handle BeforeRenderPage event
    render.BeforeRenderPage += new AcmPageEventHandler(BeforeRenderPage);

    AcmContent content = new AcmContent();

    //creating "normal" ACM contents.....        
    ....

    //Render the contents
    render.Render(content);
    
    //Save the document
    doc.Save("hello.pdf");
}

//BeforeRenderPage event handler
private void BeforeRenderPage(object sender, AcmPageEventArgs e)
{
    //Create a new text layer
    EO.Pdf.Contents.PdfTextLayer textLayer = new EO.Pdf.Contents.PdfTextLayer();

    //Use a big font, light text color and also
    //rotate the text 45 degrees
    textLayer.Font = new EO.Pdf.Drawing.PdfFont("Arial", 50);
    textLayer.NonStrokingColor = Color.LightGray;
    textLayer.GfxMatrix.Rotate(45);

    //Create the text object
    EO.Pdf.Contents.PdfTextContent textContent = new EO.Pdf.Contents.PdfTextContent("CONFIDENTIAL");
    textContent.PositionMode = EO.Pdf.Contents.PdfTextPositionMode.Offset;
    textContent.Offset = new EO.Pdf.Drawing.PdfPoint(350, 150);

    //Add the text object into the text layer object
    textLayer.Contents.Add(textContent);

    //Add the text layer into the page
    e.Page.Contents.Add(textLayer);
}

The same can be done in the AcmRender's AfterRenderPage event handler. However when AfterRenderPage is called, all "normal" ACM contents have already been placed on the page. Thus AfterRenderPage is suitable for scenarios such as a "rubber stamp" which appears on top of the regular contents.

The event argument AcmPageEventArgs contains information about the current page as well as the first and last content that will be rendered on the page. You can use this information together with each content's Tag value to derive your output.